package com.tuling.mybaitis_spring.proxy;

import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * mapper 使用代理实现依赖注入
 */
@SuppressWarnings({"rawtypes", "unchecked"})
public class MybaitisProxyFactoryBean implements FactoryBean {

	private Class interfaceClass;

	public MybaitisProxyFactoryBean(Class interfaceClass){
		this.interfaceClass = interfaceClass;
	}
	@Override
	public Object getObject() throws Exception {

		Object proxyInstance = Proxy.newProxyInstance(MybaitisProxyFactoryBean.class.getClassLoader(), new Class[]{interfaceClass},
				new InvocationHandler() {
					@Override
					public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
						return null;
					}
				});
		return proxyInstance;
	}

	@Override
	public Class<?> getObjectType() {
		return interfaceClass;
	}
}
